import java.util.Scanner;

public class Test4 {
    //依次打印数字
    public static void print(int n) {
        while (n != 0) {
            System.out.print(n % 10 + " ");
            n /= 10;
        }
    }

    //调用方法1 main + 方法名
    public static void main1(String[] args) {
        print(123);
    }


    //模拟密码登录（方法2）
    public static void login() {
        Scanner scanner = new Scanner(System.in);
        int count = 3;
        while (count != 0) {
            System.out.println("请输入你的密码！");
            String pass = scanner.nextLine();
            //在Java中写输入值的时候不能写成 if(pass == "6666666") 否则输入对的密码也无法登录成功
            if (pass.equals("666666")) {
                System.out.println("登陆成功！");
                return;
            }
            count--;
            System.out.println("你还有" + count + "次机会！");
        }
    }

    //调用方法2
    public static void main2(String[] args) {
        login();
    }


    //计算1到5阶乘的和
    public static void main3(String[] args) {
        int n = 5;
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int factorial = 1;
            for (int j = 1; j <= i; j++) {
                factorial *= j;
            }
            sum += factorial;
        }
        System.out.println("结果为：" + sum);
    }


    //求斐波那契数列的第10项
    public static int fibonacci(int n) {
        if (n <= 1) {
            return n;
        }
        int a = 0, b = 1;
        for (int i = 1; i <= n; i++) {
            int temp = b;
            b = a + b;
            a = temp;
        }
        return b;
    }

    public static void main4(String[] args) {
        int n = 10;
        int result = fibonacci(n);
        System.out.println("斐波那契数列第" + n + "项是：" + result);
    }


    //求最大值方法的重载
    //定义方法
    public static int max(int a, int b) {
        return a > b ? a : b;
    }

    public static double max(double a, double b, double c) {
        double temp = a > b ? a : b;
        return temp > c ? temp : c;
    }
    //调用方法
    public static void main5(String[] args) {
        Test4 calculator = new Test4();//创建了一个MaxValue类的实例calculator，使用new MaxValue()语句

        int intResult = calculator.max(5, 3);//结果存储在intResult变量中
        System.out.println("两个整数最大值为：" + intResult);

        double doubleResult = calculator.max(2.5, 3.7, 1.9);
        System.out.println("三个小数的最大值为：" + doubleResult);
    }
}
